#! /bin/bash

np=$1;
npstride=$2;
if  [[ $npstride != 1 ]]
then
    corenum[0]=1
    for i in `seq  $npstride $npstride $np`
    do
        corenum[$(($i/$npstride))]=$i;
        #echo ${corenum[$(($i/$npstride))]} $i
    done
else
    for i in `seq  1 $np`
    do
        corenum[$(($i-1))]=$i;
        #echo ${corenum[$(($i/$npstride))]} $i
    done
fi
total=30
a=24;
b=24;
for exe in 1d-jacobi-3p-blocking
do
    rm result/$exe-16384.txt 
    rm result/$exe-2048.txt
    for index in `seq $a $b`;
    do 
    nx=$((2 ** $index))
    t=$((2 ** ($total - $index)))
    for i in "${corenum[@]}";
    do
        export OMP_NUM_THREADS=$i;../$exe/exe-$exe 16000000 6000 16384 128 >> result/$exe-16384.txt 
        export OMP_NUM_THREADS=$i;../$exe/exe-$exe 16000000 6000  2048 128 >> result/$exe-2048.txt 
        echo  $i >> result/1d-jacobi-3p-blocking.cpulist
    done
    done
done


cat result/1d-jacobi-3p-blocking-16384.txt|awk -F "= " '{print $NF}'|paste result/1d-jacobi-3p-blocking.cpulist - - - ->  result/1d-jacobi-3p-blocking.data.txt
cat result/1d-jacobi-3p-blocking-2048.txt|awk -F "= " '{print $NF}'|paste  result/1d-jacobi-3p-blocking.data.txt - - - -> result/1d-jacobi-3p-blocking.data2.txt
echo -e "np\tscalar\tauto\tour\tour2" > result/1d-jacobi-3p-blocking.data.txt
cat result/1d-jacobi-3p-blocking.data2.txt| awk '{printf("%d\t%f\t%f\t%f\t%f\n",$1,($2>$6)?$2:  $6,($3>$7)?$3:$7,($4>$8)?$4:$8,($5>$9)?$5:$9) }' >> result/1d-jacobi-3p-blocking.data.txt
rm result/1d-jacobi-3p-blocking.cpulist
rm result/1d-jacobi-3p-blocking.data2.txt
